package org.example.mygobang.controller;

import org.apache.ibatis.annotations.Mapper;
import org.example.mygobang.model.History;
import org.example.mygobang.model.User;
import org.example.mygobang.service.MatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@RestController
@RequestMapping("/findMatch")
public class MatchController {
    @Autowired
    MatchService matchService;
    @RequestMapping("/stats")
    public ArrayList<History> getHistory(HttpServletRequest httpServletRequest) {
        HttpSession httpSession = httpServletRequest.getSession(false);
        try {
            User user = (User) httpSession.getAttribute("user");
            System.out.println(user.getUsername());
            return matchService.selectForUserId(user.getUserId());
        } catch (NullPointerException e) {
            System.out.println("未登录" + e.getMessage());
            return null;
        }
    }
}
